package edu.service;

import java.util.List;

import edu.dao.PatientDAO;
import edu.model.Patient;

public class PatientService {
	
	private PatientDAO patientDAO = null;
	

	public PatientDAO getPatientDAO() {
		return patientDAO;
	}

	public void setPatientDAO(PatientDAO PatientDAO) {
		this.patientDAO = PatientDAO;
	}
	
	public Patient getPatientById(Integer id){
		return patientDAO.findById(id);
	}
	
	
	
	public boolean savePatient(Patient Patient){
		if(patientDAO.findByPersonId(Patient.getPersonId()).isEmpty()){
			patientDAO.save(Patient);
			return true;
		}
		return false;
	}
	
	public boolean deletePatient(Integer uid){
		Patient Patient = patientDAO.findById(uid);
		if(Patient != null){
			patientDAO.delete(Patient);
			return true;
		}
		return false;
	}
	
	public boolean updatePatient(Patient Patient){
		Patient u = patientDAO.findById(Patient.getPatientId());
		if(u != null){
			patientDAO.attachDirty(Patient);
			return true;
		}
		return false;
	}
	
	@SuppressWarnings("unchecked")
	public List<Patient> getAllPatient(){
		return patientDAO.findAll();
	}
}
